package com.my.deepseek.controller;

import com.my.common.result.R;
import com.my.deepseek.model.DeepSeekRequest;
import com.my.deepseek.service.DeepSeekService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @author mars
 * @date 2025-08-31 21:45
 */
@RestController
@RequestMapping("/deepseek")
@RequiredArgsConstructor
public class DeepSeekController {
    private final DeepSeekService deepSeekService;


    @PostMapping("/chat")
    public R<String> chat(@RequestBody DeepSeekRequest request){
        return R.success(deepSeekService.generate(request));
    }

    @PostMapping("/chatStream")
    public Flux<String> chatStream(@RequestBody DeepSeekRequest request){
        return deepSeekService.generateStream(request).mapNotNull(e -> e.getResult().getOutput().getText());
    }
}
